package asia.yuanding.wechat.web.netty.manager;

import io.netty.channel.Channel;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: ChannelManager
 * @Author: YuanDing
 * @Date: 2025/8/3 21:33
 * @Description:
 */

public class ChannelManager {
    // userId -> Channel
    private static final Map<String, Channel> userChannelMap = new ConcurrentHashMap<>();

    public static void addUser(String userId, Channel channel) {
        userChannelMap.put(userId, channel);
    }

    public static void removeUser(String userId) {
        userChannelMap.remove(userId);
    }

    public static Channel getChannel(String userId) {
        return userChannelMap.get(userId);
    }

    public static Collection<Channel> getAllChannels() {
        return userChannelMap.values();
    }
}

